from flask import Blueprint, request, jsonify
import json
from database import db

bp_user = Blueprint('user', __name__)


@bp_user.route('/user')
def login():
    data = json.loads(request.data)
    mobile = data['mobile']
    password = data['password']
    sql = "select * form cuser where mobile=%s" % (mobile)
    user = db.findall(sql)
    if user:
        if user['password'] == password:
            return jsonify({'code': 200, 'userid': user['id']})
        else:
            return jsonify({'code': 10011})
    else:
        return jsonify({'code': 10010})
